package com.gui;

/**
 *
 * @author Jean Elio di Angelis Vasconcelos, Carla Sukeyosi, Matheus Emanuel, Heitor Carvalho
 */
import com.data.DataManager;
import com.data.IODataHandler;
import com.util.ArchiveSelector;
import com.util.Clock;
import com.util.Helper;
import com.vo.Contact;
import com.vo.Event;
import com.vo.Group;
import com.vo.Interval;
import com.vo.Note;
import com.vo.User;
import java.awt.event.MouseEvent;
import java.io.File;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Timer;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Elephant extends javax.swing.JFrame {
    
    private Timer time;
    private User user;
    private DataManager dataManager;
    private String userImgPath;
    private Event eventKey;
    private Contact contactKey;
    private Group groupKey;
    
    public Elephant() 
    {
        initComponents();
        initialLoad();
        loadImages();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPanel_jDesktopPanel = new javax.swing.JDesktopPane();
        time_jPanel = new javax.swing.JPanel();
        time_jLabel = new javax.swing.JLabel();
        wellcome_jLabel = new javax.swing.JLabel();
        menu_jPanel = new javax.swing.JPanel();
        perfil_jButton = new javax.swing.JButton();
        events_jButton = new javax.swing.JButton();
        contacts_jButton = new javax.swing.JButton();
        config_jButton = new javax.swing.JButton();
        groups_jButton = new javax.swing.JButton();
        help_jButton = new javax.swing.JButton();
        perfil_jInternalFrame = new javax.swing.JInternalFrame();
        userName_jLabel = new javax.swing.JLabel();
        userEmail_jLabel = new javax.swing.JLabel();
        userDescription_jLabel = new javax.swing.JLabel();
        userImage_jLabel = new javax.swing.JLabel();
        userName_jTextField = new javax.swing.JTextField();
        userEmail_jTextField = new javax.swing.JTextField();
        saveInfo_jButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        userDescription_jTextArea = new javax.swing.JTextArea();
        events_jInternalFrame = new javax.swing.JInternalFrame();
        jScrollPane3 = new javax.swing.JScrollPane();
        futureEvents_jList = new javax.swing.JList();
        futureEvents_jLabel = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        pastEvents_jList = new javax.swing.JList();
        pastEvents_jLabel = new javax.swing.JLabel();
        c_g_jPanel = new javax.swing.JPanel();
        eventContacts_jComboBox = new javax.swing.JComboBox();
        eventContacts_jLabel = new javax.swing.JLabel();
        contactsSearch_jLabel = new javax.swing.JLabel();
        contactSearch_jTextField = new javax.swing.JTextField();
        contacts_jComboBox = new javax.swing.JComboBox();
        addContact_jButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        addGroup_jButton = new javax.swing.JButton();
        groups_jComboBox = new javax.swing.JComboBox();
        groups_jLabel = new javax.swing.JLabel();
        eventGroups_jComboBox = new javax.swing.JComboBox();
        contacts_jLabel1 = new javax.swing.JLabel();
        eventInfo_jPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        eventDescription_jTextArea = new javax.swing.JTextArea();
        eventDescription_jLabel = new javax.swing.JLabel();
        notesQuantity_jLabel = new javax.swing.JLabel();
        notesQuant_jLabel = new javax.swing.JLabel();
        eventName_jLabel = new javax.swing.JLabel();
        eventName_jTextField = new javax.swing.JTextField();
        eventType_jLabel = new javax.swing.JLabel();
        eventType_jTextField = new javax.swing.JTextField();
        cleanAllEventFields_jButton = new javax.swing.JButton();
        eventDates_jPanel = new javax.swing.JPanel();
        eventStartDate_jTextField = new javax.swing.JFormattedTextField();
        eventStartHour_jTextField = new javax.swing.JFormattedTextField();
        eventEndDate_jTextField = new javax.swing.JFormattedTextField();
        eventEndHour_jTextField = new javax.swing.JFormattedTextField();
        EndDate_jLabel = new javax.swing.JLabel();
        eventEndHour_jLabel = new javax.swing.JLabel();
        eventStartHour_jLabel = new javax.swing.JLabel();
        eventStartDate_jLabel = new javax.swing.JLabel();
        notesButton_jButton = new javax.swing.JButton();
        eventButtons_jPanel = new javax.swing.JPanel();
        deleteEvent_jButton = new javax.swing.JButton();
        saveEventInfo_jButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Elephant - Beta Version");
        setName("MainWindow"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        desktopPanel_jDesktopPanel.setBackground(new java.awt.Color(255, 255, 255));
        desktopPanel_jDesktopPanel.setToolTipText("Área de Trabalho");
        desktopPanel_jDesktopPanel.setFont(new java.awt.Font("Tahoma", 0, 14));
        desktopPanel_jDesktopPanel.setPreferredSize(new java.awt.Dimension(1000, 610));

        time_jPanel.setToolTipText("Relógio");
        time_jPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                time_jPanelMouseDragged(evt);
            }
        });

        time_jLabel.setText("Time/Hour");

        javax.swing.GroupLayout time_jPanelLayout = new javax.swing.GroupLayout(time_jPanel);
        time_jPanel.setLayout(time_jPanelLayout);
        time_jPanelLayout.setHorizontalGroup(
            time_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, time_jPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(time_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        time_jPanelLayout.setVerticalGroup(
            time_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, time_jPanelLayout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addComponent(time_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        time_jPanel.setBounds(870, 550, 110, 50);
        desktopPanel_jDesktopPanel.add(time_jPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        wellcome_jLabel.setFont(new java.awt.Font("MoolBoran", 0, 24));
        wellcome_jLabel.setForeground(new java.awt.Color(153, 153, 153));
        wellcome_jLabel.setText("Bem vindo");
        wellcome_jLabel.setBounds(0, 0, 200, 50);
        desktopPanel_jDesktopPanel.add(wellcome_jLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        menu_jPanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                menu_jPanelMouseDragged(evt);
            }
        });

        perfil_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                perfil_jButtonActionPerformed(evt);
            }
        });

        events_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                events_jButtonActionPerformed(evt);
            }
        });

        contacts_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contacts_jButtonActionPerformed(evt);
            }
        });

        config_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                config_jButtonActionPerformed(evt);
            }
        });

        groups_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groups_jButtonActionPerformed(evt);
            }
        });

        help_jButton.setToolTipText("Ajuda");
        help_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                help_jButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout menu_jPanelLayout = new javax.swing.GroupLayout(menu_jPanel);
        menu_jPanel.setLayout(menu_jPanelLayout);
        menu_jPanelLayout.setHorizontalGroup(
            menu_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(menu_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(perfil_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(events_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(contacts_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(groups_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(config_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(help_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );
        menu_jPanelLayout.setVerticalGroup(
            menu_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(menu_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(menu_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(help_jButton, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(config_jButton, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(groups_jButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(contacts_jButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(events_jButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(perfil_jButton, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE))
                .addContainerGap())
        );

        menu_jPanel.setBounds(10, 480, 700, 110);
        desktopPanel_jDesktopPanel.add(menu_jPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        perfil_jInternalFrame.setClosable(true);
        perfil_jInternalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        perfil_jInternalFrame.setIconifiable(true);
        perfil_jInternalFrame.setResizable(true);
        perfil_jInternalFrame.setTitle("Elephant - Perfil de Usuário");
        perfil_jInternalFrame.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        perfil_jInternalFrame.setFrameIcon(null);
        perfil_jInternalFrame.setMaximumSize(new java.awt.Dimension(99999, 99999));
        perfil_jInternalFrame.setMinimumSize(new java.awt.Dimension(546, 342));
        perfil_jInternalFrame.setVerifyInputWhenFocusTarget(false);

        userName_jLabel.setText("Nome:");

        userEmail_jLabel.setText("E-mail:");

        userDescription_jLabel.setText("Descrição:");

        userImage_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        userImage_jLabel.setText("Clique para adicionar Imagem");
        userImage_jLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        userImage_jLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                userImage_jLabelMouseClicked(evt);
            }
        });

        saveInfo_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveInfo_jButtonActionPerformed(evt);
            }
        });

        userDescription_jTextArea.setColumns(20);
        userDescription_jTextArea.setRows(5);
        jScrollPane2.setViewportView(userDescription_jTextArea);

        javax.swing.GroupLayout perfil_jInternalFrameLayout = new javax.swing.GroupLayout(perfil_jInternalFrame.getContentPane());
        perfil_jInternalFrame.getContentPane().setLayout(perfil_jInternalFrameLayout);
        perfil_jInternalFrameLayout.setHorizontalGroup(
            perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(perfil_jInternalFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(userEmail_jLabel)
                    .addComponent(userName_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(userDescription_jLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2)
                    .addComponent(userEmail_jTextField)
                    .addComponent(userName_jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(userImage_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveInfo_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        perfil_jInternalFrameLayout.setVerticalGroup(
            perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(perfil_jInternalFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(perfil_jInternalFrameLayout.createSequentialGroup()
                        .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(userName_jLabel)
                            .addComponent(userName_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(userEmail_jLabel)
                            .addComponent(userEmail_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(userImage_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(perfil_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(userDescription_jLabel)
                    .addComponent(jScrollPane2)
                    .addComponent(saveInfo_jButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        perfil_jInternalFrame.setBounds(50, 30, 546, 342);
        desktopPanel_jDesktopPanel.add(perfil_jInternalFrame, javax.swing.JLayeredPane.DEFAULT_LAYER);

        events_jInternalFrame.setClosable(true);
        events_jInternalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        events_jInternalFrame.setIconifiable(true);
        events_jInternalFrame.setResizable(true);
        events_jInternalFrame.setTitle("Elephant - Eventos");
        events_jInternalFrame.setFrameIcon(null);
        events_jInternalFrame.setMinimumSize(new java.awt.Dimension(931, 455));
        events_jInternalFrame.setPreferredSize(new java.awt.Dimension(931, 455));

        futureEvents_jList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                futureEvents_jListFocusLost(evt);
            }
        });
        futureEvents_jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                futureEvents_jListValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(futureEvents_jList);

        futureEvents_jLabel.setText("Eventos futuros:");

        pastEvents_jList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                pastEvents_jListFocusLost(evt);
            }
        });
        pastEvents_jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                pastEvents_jListValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(pastEvents_jList);

        pastEvents_jLabel.setText("Eventos passados:");

        c_g_jPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        eventContacts_jLabel.setText("Contatos do Evento:");

        contactsSearch_jLabel.setText("Busque um contato:");

        contactSearch_jTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                contactSearch_jTextFieldMousePressed(evt);
            }
        });

        addContact_jButton.setText("Adicionar Contato");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        addGroup_jButton.setText("Adicionar Grupo");

        groups_jLabel.setText("Todos os grupos:");

        eventGroups_jComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eventGroups_jComboBoxActionPerformed(evt);
            }
        });

        contacts_jLabel1.setText("Grupos do Evento:");

        javax.swing.GroupLayout c_g_jPanelLayout = new javax.swing.GroupLayout(c_g_jPanel);
        c_g_jPanel.setLayout(c_g_jPanelLayout);
        c_g_jPanelLayout.setHorizontalGroup(
            c_g_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, c_g_jPanelLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(c_g_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(addContact_jButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, c_g_jPanelLayout.createSequentialGroup()
                        .addComponent(contactsSearch_jLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(contactSearch_jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                    .addComponent(contacts_jComboBox, 0, 180, Short.MAX_VALUE)
                    .addComponent(eventContacts_jComboBox, 0, 180, Short.MAX_VALUE)
                    .addComponent(eventContacts_jLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(c_g_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(contacts_jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(eventGroups_jComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 160, Short.MAX_VALUE)
                    .addComponent(groups_jComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 160, Short.MAX_VALUE)
                    .addComponent(groups_jLabel)
                    .addComponent(addGroup_jButton, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                .addContainerGap())
        );
        c_g_jPanelLayout.setVerticalGroup(
            c_g_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(c_g_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(contacts_jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(eventGroups_jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(groups_jLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(groups_jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addGroup_jButton)
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
            .addGroup(c_g_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(eventContacts_jLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(eventContacts_jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(c_g_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(contactSearch_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(contactsSearch_jLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(contacts_jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addContact_jButton)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        eventDescription_jTextArea.setColumns(20);
        eventDescription_jTextArea.setRows(5);
        jScrollPane1.setViewportView(eventDescription_jTextArea);

        eventDescription_jLabel.setText("Descrição:");

        notesQuantity_jLabel.setText("Quant. anotações:");

        notesQuant_jLabel.setText("0");

        eventName_jLabel.setText("Nome:");

        eventType_jLabel.setText("Tipo:");

        cleanAllEventFields_jButton.setText("Limpar Campos");
        cleanAllEventFields_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cleanAllEventFields_jButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout eventInfo_jPanelLayout = new javax.swing.GroupLayout(eventInfo_jPanel);
        eventInfo_jPanel.setLayout(eventInfo_jPanelLayout);
        eventInfo_jPanelLayout.setHorizontalGroup(
            eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(eventInfo_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(eventInfo_jPanelLayout.createSequentialGroup()
                        .addGroup(eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eventDescription_jLabel)
                            .addComponent(eventName_jLabel)
                            .addComponent(eventType_jLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eventType_jTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                            .addComponent(eventName_jTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)))
                    .addGroup(eventInfo_jPanelLayout.createSequentialGroup()
                        .addComponent(notesQuantity_jLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(notesQuant_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                        .addComponent(cleanAllEventFields_jButton)))
                .addContainerGap())
        );
        eventInfo_jPanelLayout.setVerticalGroup(
            eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(eventInfo_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(eventInfo_jPanelLayout.createSequentialGroup()
                        .addComponent(eventName_jLabel)
                        .addGap(18, 18, 18)
                        .addComponent(eventType_jLabel)
                        .addGap(18, 18, 18)
                        .addComponent(eventDescription_jLabel))
                    .addGroup(eventInfo_jPanelLayout.createSequentialGroup()
                        .addComponent(eventName_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(eventType_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(eventInfo_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(notesQuantity_jLabel)
                    .addComponent(notesQuant_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cleanAllEventFields_jButton))
                .addContainerGap())
        );

        eventStartDate_jTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

        eventStartHour_jTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        eventEndDate_jTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

        eventEndHour_jTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        EndDate_jLabel.setText("Data de Término:");

        eventEndHour_jLabel.setText("Hora de Término:");

        eventStartHour_jLabel.setText("Hora de Início:");

        eventStartDate_jLabel.setText("Data de Início:");

        javax.swing.GroupLayout eventDates_jPanelLayout = new javax.swing.GroupLayout(eventDates_jPanel);
        eventDates_jPanel.setLayout(eventDates_jPanelLayout);
        eventDates_jPanelLayout.setHorizontalGroup(
            eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(eventDates_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, eventDates_jPanelLayout.createSequentialGroup()
                        .addComponent(eventEndHour_jLabel)
                        .addGap(18, 18, 18)
                        .addComponent(eventEndHour_jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, eventDates_jPanelLayout.createSequentialGroup()
                        .addComponent(EndDate_jLabel)
                        .addGap(18, 18, 18)
                        .addComponent(eventEndDate_jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, eventDates_jPanelLayout.createSequentialGroup()
                        .addComponent(eventStartHour_jLabel)
                        .addGap(31, 31, 31)
                        .addComponent(eventStartHour_jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, eventDates_jPanelLayout.createSequentialGroup()
                        .addComponent(eventStartDate_jLabel)
                        .addGap(31, 31, 31)
                        .addComponent(eventStartDate_jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)))
                .addContainerGap())
        );
        eventDates_jPanelLayout.setVerticalGroup(
            eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, eventDates_jPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(eventStartDate_jLabel)
                    .addComponent(eventStartDate_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(eventStartHour_jLabel)
                    .addComponent(eventStartHour_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(EndDate_jLabel)
                    .addComponent(eventEndDate_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(eventDates_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(eventEndHour_jLabel)
                    .addComponent(eventEndHour_jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        notesButton_jButton.setToolTipText("Anotações");
        notesButton_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notesButton_jButtonActionPerformed(evt);
            }
        });

        deleteEvent_jButton.setToolTipText("Deletar Evento");
        deleteEvent_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteEvent_jButtonActionPerformed(evt);
            }
        });

        saveEventInfo_jButton.setToolTipText("Salvar Alterações");
        saveEventInfo_jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveEventInfo_jButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout eventButtons_jPanelLayout = new javax.swing.GroupLayout(eventButtons_jPanel);
        eventButtons_jPanel.setLayout(eventButtons_jPanelLayout);
        eventButtons_jPanelLayout.setHorizontalGroup(
            eventButtons_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, eventButtons_jPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(deleteEvent_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(saveEventInfo_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        eventButtons_jPanelLayout.setVerticalGroup(
            eventButtons_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(eventButtons_jPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(eventButtons_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(saveEventInfo_jButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteEvent_jButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout events_jInternalFrameLayout = new javax.swing.GroupLayout(events_jInternalFrame.getContentPane());
        events_jInternalFrame.getContentPane().setLayout(events_jInternalFrameLayout);
        events_jInternalFrameLayout.setHorizontalGroup(
            events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                        .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                            .addComponent(pastEvents_jLabel)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eventDates_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(eventInfo_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(notesButton_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(eventButtons_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(c_g_jPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(143, 143, 143))
                    .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                        .addComponent(futureEvents_jLabel)
                        .addContainerGap(833, Short.MAX_VALUE))))
        );
        events_jInternalFrameLayout.setVerticalGroup(
            events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                        .addComponent(futureEvents_jLabel)
                        .addGap(11, 11, 11)
                        .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pastEvents_jLabel)
                                .addGap(15, 15, 15)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(events_jInternalFrameLayout.createSequentialGroup()
                                .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(c_g_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(eventInfo_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(events_jInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(eventDates_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(eventButtons_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(35, 35, 35))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, events_jInternalFrameLayout.createSequentialGroup()
                        .addComponent(notesButton_jButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(153, 153, 153))))
        );

        events_jInternalFrame.setBounds(20, 40, 940, 460);
        desktopPanel_jDesktopPanel.add(events_jInternalFrame, javax.swing.JLayeredPane.DEFAULT_LAYER);
        events_jInternalFrame.getAccessibleContext().setAccessibleDescription("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPanel_jDesktopPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 1000, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPanel_jDesktopPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 610, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        desktopPanel_jDesktopPanel.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
       
    }//GEN-LAST:event_formWindowClosed

    private void menu_jPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menu_jPanelMouseDragged

        startDraging(menu_jPanel, evt);     }//GEN-LAST:event_menu_jPanelMouseDragged

    private void time_jPanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_time_jPanelMouseDragged

        startDraging(time_jPanel, evt);     }//GEN-LAST:event_time_jPanelMouseDragged

    private void perfil_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_perfil_jButtonActionPerformed
        perfil_jInternalFrame.setVisible(true);
    }//GEN-LAST:event_perfil_jButtonActionPerformed

    private void events_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_events_jButtonActionPerformed
        events_jInternalFrame.setVisible(true);
    }//GEN-LAST:event_events_jButtonActionPerformed

    private void contacts_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contacts_jButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_contacts_jButtonActionPerformed

    private void config_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_config_jButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_config_jButtonActionPerformed

    private void groups_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groups_jButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_groups_jButtonActionPerformed

    private void saveInfo_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveInfo_jButtonActionPerformed
     saveUserInfo();
    }//GEN-LAST:event_saveInfo_jButtonActionPerformed

    private void userImage_jLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_userImage_jLabelMouseClicked
        try
        {
            ArchiveSelector chooser = new ArchiveSelector();
//            if (userImgPath != null)
//                chooser.setOldPath(userImgPath);
            userImgPath = chooser.getFilePath() != null? chooser.getFilePath(): "";
            if (!userImgPath.equals(""))
            {
                System.out.println(userImgPath);
                userImage_jLabel.setText("");
                userImage_jLabel.setIcon(new ImageIcon(userImgPath));
            }
        } catch (Exception ex)
        {
            System.err.println(ex.getMessage());
        }
    }//GEN-LAST:event_userImage_jLabelMouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        //Finaliza o timer do relogio         
        time.cancel();
        
        //Salva todas as informacoes no disco
        dataManager.saveAll();
    }//GEN-LAST:event_formWindowClosing

    private void saveEventInfo_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveEventInfo_jButtonActionPerformed
        if (validateEventForm())
        {
            buildAndSaveEvent();
            clearEventFields();
            loadEventsLists();
            deleteEvent_jButton.setEnabled(true);
        }
        else
        {
            JOptionPane.showMessageDialog(this, "Por favor, preencha os campos corretamente.");
            eventName_jTextField.requestFocus();
        }
    }//GEN-LAST:event_saveEventInfo_jButtonActionPerformed

    private void eventGroups_jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eventGroups_jComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_eventGroups_jComboBoxActionPerformed

    private void notesButton_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notesButton_jButtonActionPerformed
        NotesForm anotForm = new NotesForm(eventKey, this);
        anotForm.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_notesButton_jButtonActionPerformed

    private void deleteEvent_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteEvent_jButtonActionPerformed
        if (eventKey != null && !eventKey.getName().equals(""))
        {
            try
            {
                if (dataManager.removeItem(eventKey))
                {
                    JOptionPane.showMessageDialog(this, "Evento removido com sucesso.");
                    clearEventFields();
                    loadEventsLists();
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "Erro ao tentar remover evento.");
                    return;
                }
            } catch (Exception ex)
            {
                System.err.println(ex.getMessage());
            }
        }
    }//GEN-LAST:event_deleteEvent_jButtonActionPerformed

    private void help_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_help_jButtonActionPerformed
        String content = "Desenvolvido por: \n\nCarla Sukeyosi; "
                + "\nJean Vasconcelos; \nMatheus Emanuel; \nHeitor Carvalho;"
                + "\n\n Dica: Para ver o texto dos botões deixe o mouse parado por alguns segundos\n"
                + "em cima do botão. \n\n"
                + "Campina Grande 24/11/2011.";
        JOptionPane.showMessageDialog(this, content);
    }//GEN-LAST:event_help_jButtonActionPerformed

    private void cleanAllEventFields_jButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cleanAllEventFields_jButtonActionPerformed
        deleteEvent_jButton.setEnabled(false);
        clearEventFields();
        eventKey = new Event("", "", new Interval());
    }//GEN-LAST:event_cleanAllEventFields_jButtonActionPerformed

    private void futureEvents_jListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_futureEvents_jListValueChanged
        int index = futureEvents_jList.getSelectedIndex();
        if (!(index < 0))
        {
            deleteEvent_jButton.setEnabled(true);
            eventKey = dataManager.getFutureEventList().get(futureEvents_jList.getSelectedIndex());
            loadEventInfo();
        }
    }//GEN-LAST:event_futureEvents_jListValueChanged

    private void pastEvents_jListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_pastEvents_jListValueChanged
        int index = pastEvents_jList.getSelectedIndex();
        if (!(index < 0))
        {
            deleteEvent_jButton.setEnabled(true);
            eventKey = dataManager.getPastEventList().get(pastEvents_jList.getSelectedIndex());
            loadEventInfo();
        }
    }//GEN-LAST:event_pastEvents_jListValueChanged

    private void pastEvents_jListFocusLost(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pastEvents_jListFocusLost
        pastEvents_jList.clearSelection();
    }//GEN-LAST:event_pastEvents_jListFocusLost

    private void futureEvents_jListFocusLost(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_futureEvents_jListFocusLost
        futureEvents_jList.clearSelection();
    }//GEN-LAST:event_futureEvents_jListFocusLost

    private void contactSearch_jTextFieldMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_contactSearch_jTextFieldMousePressed
        String search = contactSearch_jTextField.getText();
        contacts_jComboBox.removeAllItems();
        try 
        {
            List<Contact> contactList = dataManager.contactSearch(search);
            for (Contact c : contactList)
            {
                contacts_jComboBox.addItem(c.getName());
            }    
        }catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }//GEN-LAST:event_contactSearch_jTextFieldMousePressed
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Elephant.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Elephant.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Elephant.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Elephant.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Elephant().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel EndDate_jLabel;
    private javax.swing.JButton addContact_jButton;
    private javax.swing.JButton addGroup_jButton;
    private javax.swing.JPanel c_g_jPanel;
    private javax.swing.JButton cleanAllEventFields_jButton;
    private javax.swing.JButton config_jButton;
    private javax.swing.JTextField contactSearch_jTextField;
    private javax.swing.JLabel contactsSearch_jLabel;
    private javax.swing.JButton contacts_jButton;
    private javax.swing.JComboBox contacts_jComboBox;
    private javax.swing.JLabel contacts_jLabel1;
    private javax.swing.JButton deleteEvent_jButton;
    private javax.swing.JDesktopPane desktopPanel_jDesktopPanel;
    private javax.swing.JPanel eventButtons_jPanel;
    private javax.swing.JComboBox eventContacts_jComboBox;
    private javax.swing.JLabel eventContacts_jLabel;
    private javax.swing.JPanel eventDates_jPanel;
    private javax.swing.JLabel eventDescription_jLabel;
    private javax.swing.JTextArea eventDescription_jTextArea;
    private javax.swing.JFormattedTextField eventEndDate_jTextField;
    private javax.swing.JLabel eventEndHour_jLabel;
    private javax.swing.JFormattedTextField eventEndHour_jTextField;
    private javax.swing.JComboBox eventGroups_jComboBox;
    private javax.swing.JPanel eventInfo_jPanel;
    private javax.swing.JLabel eventName_jLabel;
    private javax.swing.JTextField eventName_jTextField;
    private javax.swing.JLabel eventStartDate_jLabel;
    private javax.swing.JFormattedTextField eventStartDate_jTextField;
    private javax.swing.JLabel eventStartHour_jLabel;
    private javax.swing.JFormattedTextField eventStartHour_jTextField;
    private javax.swing.JLabel eventType_jLabel;
    private javax.swing.JTextField eventType_jTextField;
    private javax.swing.JButton events_jButton;
    private javax.swing.JInternalFrame events_jInternalFrame;
    private javax.swing.JLabel futureEvents_jLabel;
    private javax.swing.JList futureEvents_jList;
    private javax.swing.JButton groups_jButton;
    private javax.swing.JComboBox groups_jComboBox;
    private javax.swing.JLabel groups_jLabel;
    private javax.swing.JButton help_jButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel menu_jPanel;
    private javax.swing.JButton notesButton_jButton;
    private javax.swing.JLabel notesQuant_jLabel;
    private javax.swing.JLabel notesQuantity_jLabel;
    private javax.swing.JLabel pastEvents_jLabel;
    private javax.swing.JList pastEvents_jList;
    private javax.swing.JButton perfil_jButton;
    private javax.swing.JInternalFrame perfil_jInternalFrame;
    private javax.swing.JButton saveEventInfo_jButton;
    private javax.swing.JButton saveInfo_jButton;
    private javax.swing.JLabel time_jLabel;
    private javax.swing.JPanel time_jPanel;
    private javax.swing.JLabel userDescription_jLabel;
    private javax.swing.JTextArea userDescription_jTextArea;
    private javax.swing.JLabel userEmail_jLabel;
    private javax.swing.JTextField userEmail_jTextField;
    private javax.swing.JLabel userImage_jLabel;
    private javax.swing.JLabel userName_jLabel;
    private javax.swing.JTextField userName_jTextField;
    private javax.swing.JLabel wellcome_jLabel;
    // End of variables declaration//GEN-END:variables
    
    /**
     * Carrega e instancia variaveis iniciais tais como funcoes do relogio
     */
    private void initialLoad() 
    {
        //Configuracao dataManager
        dataManager = new DataManager();
        //fim configuracao dataManager

        //Carregando informacoes do usuario
        loadUInfo();
        //fim informacoes do usuario
        
        //Configuracoes do relogio
        time = new Timer();
        Clock task = new Clock(this.time_jLabel);
        time.scheduleAtFixedRate(task, 0, 1);
        time_jPanel.setOpaque(false);
        //Fim configuracoes relogio
        
        //Carregando informacoes dos eventos
        loadEventsLists();
        //Fim informacoes dos eventos
        
        //Tirando o fundo opaco do menu de botoes
        menu_jPanel.setOpaque(false);
    }
    
    /**
     * Carrega imagens e icones do sistema
     */
    private void loadImages() 
    {
        String path = "src" + File.separator + "com" + File.separator + 
                "graphic" + File.separator + "icons" + File.separator;
        ImageIcon clockIc = new ImageIcon(path + "clock.png");
        this.time_jLabel.setIcon(clockIc);
        clockIc = new ImageIcon(path + "elephant48x48.png");
        this.wellcome_jLabel.setIcon(clockIc);
        clockIc = new ImageIcon(path + "userIcon.png");
        this.perfil_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "contactIcon.png");
        this.contacts_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "eventIcon.png");
        this.events_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "groupIcon.png");
        this.groups_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "configIcon.png");
        this.config_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "saveIcon.jpg");
        this.saveInfo_jButton.setIcon(clockIc);
        this.saveEventInfo_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "elephant.png");
        this.events_jInternalFrame.setFrameIcon(clockIc);
        this.perfil_jInternalFrame.setFrameIcon(clockIc);
        this.setIconImage(clockIc.getImage());
        clockIc = new ImageIcon(path + "deleteIcon.png");
        this.deleteEvent_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "noteIcon.png");
        this.notesButton_jButton.setIcon(clockIc);
        clockIc = new ImageIcon(path + "helpIcon.png");
        this.help_jButton.setIcon(clockIc);
    }
    
    /**
     * Permite que os paineis do sistema possam ser arrastados
     * @param panel panel a ser arrastado
     */
    private void startDraging(JPanel panel, MouseEvent evt) 
    {
         int xSel = panel.getLocation().x;  
         int ySel = panel.getLocation().y;  
         panel.setLocation((evt.getX()  + xSel )- (panel.getWidth() / 2),(evt.getY() + ySel) - (panel.getHeight() / 2));  
    }
    
    /**
     * Carrega e exibe informacoes do usuario
     */
    private void loadUInfo()
    {
        user = dataManager.getUser();
        if (user != null)
        {
            if (user.getName() != null)
                wellcome_jLabel.setText("Bem vindo(a), " + user.getName() + ".");
            userDescription_jTextArea.setText(user.getDescription());
            userEmail_jTextField.setText(user.getEmail());
            userName_jTextField.setText(user.getName());
            if (user.getImagePath() != null)
                userImage_jLabel.setIcon(new ImageIcon (user.getImagePath()));
        } else
        {
            user = new User();
            dataManager.setUser(user);
        }
    }
    
    /**
     * Valida os campos de texto do usuario
     * @return se todos os campos possuirem dados retorna true
     */
    private boolean validateUser() 
    {
        return !userName_jTextField.getText().equals("") &&
                !userEmail_jTextField.getText().equals("");
    }
    
    /**
     * Valida e salva os dados do usuario no disco
     */
    private void saveUserInfo() 
    {
        if (validateUser())
        {
            user.setDescription(userDescription_jTextArea.getText());
            user.setEmail(userEmail_jTextField.getText());
            user.setName(userName_jTextField.getText());
            if (user.getImagePath() != null)
            {
                IODataHandler.removeImage(user.getImagePath());
            }
            if (userImgPath != null && !userImgPath.equals(""))
                user.setImagePath(userImgPath);
            dataManager.setUser(user);
            loadUInfo();
            JOptionPane.showMessageDialog(this, "Dados alterados com sucesso!");
        }
        else
            JOptionPane.showMessageDialog(this, "Por favor, Preencha os campos corretamente.");
    }

    /**
     * Carrega as listas de eventos e a lista de grupos de contatos.
     */
    private void loadEventsLists() 
    {
        ArrayList<String> future = new ArrayList<String>();
        for (Event e: dataManager.getFutureEventList())
            future.add(e.getName());
        
        ArrayList<String> past = new ArrayList<String>();
        for (Event e: dataManager.getPastEventList())        
            past.add(e.getName());

        if (future.size() > 0)
        {
            futureEvents_jList.setListData(future.toArray());
        }
        else
            futureEvents_jList.setListData(new Object[0]);
        if (past.size() > 0)
        {
            pastEvents_jList.setListData(past.toArray());
        }
        else
            pastEvents_jList.setListData(new Object[0]);
        
        for (Group g : dataManager.getGroupList())
        {
            groups_jComboBox.addItem(g.getName());
        }
    }
    
    /**
     * Limpa todos os campos da janela Eventos, inclusive seus combobox.
     */
    private void clearEventFields() 
    {
        eventContacts_jComboBox.removeAllItems();
        eventDescription_jTextArea.setText("");
        eventEndDate_jTextField.setText("");
        eventEndHour_jTextField.setText("");
        eventStartDate_jTextField.setText("");
        eventStartHour_jTextField.setText("");
        eventGroups_jComboBox.removeAllItems();
        eventName_jTextField.setText("");
        eventType_jTextField.setText("");
        notesQuant_jLabel.setText("");
    }
    
    /**
     * Valida o formulario na hora da criacao de um evento, verificando se 
     * todos os campos obrigatorios foram preenchidos.
     * @return verdadeiro no caso dos requisitos serem atendidos
     */
    private boolean validateEventForm() 
    {
        return !eventEndDate_jTextField.getText().equals("") &&
                !eventEndHour_jTextField.getText().equals("") &&
                !eventStartDate_jTextField.getText().equals("") &&
                !eventStartHour_jTextField.getText().equals("") &&
                !eventName_jTextField.getText().equals("") &&
                !eventType_jTextField.getText().equals("") &&
                !eventDescription_jTextArea.getText().equals("");
    }
    
    /**
     * Cria e salva um novo evento para ser salvo, bem como verifica a existencia
     * de conflito com algum outro evento e sugere apagar o evento em conflito.
     */
    private void buildAndSaveEvent() 
    {
        //Criacao do evento a ser salvo
        Event newEvent = new Event(eventName_jTextField.getText(), eventType_jTextField.getText(), null);
        newEvent.setDescription(eventDescription_jTextArea.getText());
        
        List<Note> list = eventKey.getNotes();
        
        for (Note n : list)
        {
            newEvent.addNote(n);
        }
        //Codigo para quebra e conversao (criacao do intervalo)
        // da data em inteiros normais para serem setados no calendar.
        int[] startDate = Helper.breakDate(eventStartDate_jTextField.getText(), 
                eventStartHour_jTextField.getText(), true);
        int[] endDate = Helper.breakDate(eventEndDate_jTextField.getText(), 
                eventEndHour_jTextField.getText(), true);
        
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();

        start.set(startDate[2], startDate[1], startDate[0], startDate[3], startDate[4]);
        end.set(endDate[2], endDate[1], endDate[0], endDate[3], endDate[4]);
        
        Interval in = new Interval();
        in.setStartCalendar(start);
        in.setEndCalendar(end);
        
        newEvent.setInterval(in);
        //Fim do codigo para criacao do intervalo.

        try
        {
            //Codigo que verifica se existe um conflito do novo evento
            //com algum outro da lista de eventos.
            for (Event e : dataManager.geteList())
            {
                    if (e.getInterval().isConflicted(newEvent.getInterval()))
                    {
                        if (!(e.hashCode() == eventKey.hashCode()))
                        {
                            int answer = JOptionPane.showConfirmDialog(this, "Este evento está em conflito com: " + e.getName()
                                    + " Deseja apagá-lo?", "Excluir Evento.",  JOptionPane.YES_NO_OPTION);
                            if (answer == JOptionPane.YES_OPTION)
                            {
                                    dataManager.removeItem(e);
                            } else
                            {
                                return;
                            }
                        }
                    }
            }
            //Fim do codigo para verificacao de conflito de eventos.
            
            //Adicionando o evento no sistema
            if (dataManager.addEvent(newEvent, eventKey))
            {
                JOptionPane.showMessageDialog(this, "Evento adicionado com sucesso!");
            }   
            else
                JOptionPane.showMessageDialog(this, "Erro ao adicionar evento.");
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }
    
    /**
     * Altera o evento currente no sistema
     * @param event novo evento
     */
    public void setEventKey(Event event) 
    {
        eventKey = event;
    }

    private void loadEventInfo() 
    {
        if (eventKey != null)
        {
            eventContacts_jComboBox.removeAllItems();
            eventGroups_jComboBox.removeAllItems();

            List<Contact> li = eventKey.getContacts();
            List<Group> groups = dataManager.getGroupList();
            List<String> groupNames = new ArrayList<String>();

            for (Contact c: li)
            {
                eventContacts_jComboBox.addItem(c.getName());
                for (Group g : groups)
                {
                    if (c.getGroups().contains(g.hashCode()))
                        if (!groupNames.contains(g.getName()))
                            eventGroups_jComboBox.addItem(g.getName());
                }
            }

            DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);

            int startMinute = eventKey.getInterval().getStartCalendar().get(Calendar.MINUTE);
            int startHour = eventKey.getInterval().getStartCalendar().get(Calendar.HOUR_OF_DAY);
            int endHour = eventKey.getInterval().getEndCalendar().get(Calendar.HOUR_OF_DAY);
            int endMinute = eventKey.getInterval().getEndCalendar().get(Calendar.MINUTE);

            eventStartDate_jTextField.setText(df.format(eventKey.getInterval().getStartCalendar().getTime()));
            eventEndDate_jTextField.setText(df.format(eventKey.getInterval().getEndCalendar().getTime()));

            eventEndHour_jTextField.setText(endHour + ":" + endMinute);
            eventStartHour_jTextField.setText(startHour + ":" + startMinute);

            eventName_jTextField.setText(eventKey.getName());
            eventType_jTextField.setText(eventKey.getType());
            eventDescription_jTextArea.setText(eventKey.getDescription());
            notesQuant_jLabel.setText(eventKey.getNotes().size()+"");
        }
    }
}
